package com.luo.bak;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.sql.SQLException;
//
//@RestController
//@RequestMapping("/test")
public class TestController {
    @RequestMapping("/error01")
    public String error(@RequestParam String a){
        //http 协议中除了字节流(视频，音屏，文件...)，剩下的都是字符流行为(只能传递字符串）
        try {
            Integer.parseInt(a);
        }catch (NumberFormatException e){
            return "请输入全整数数字";
        }

        return "转换成功的a= " +a;
    }

    @RequestMapping("/error02")
    public String error02(@RequestParam int a){
        return "转换成功的a= " +a;
    }

    @ExceptionHandler(NumberFormatException.class)
    public String checkNumberFormatException(){
        return "NumberFormatException请输入全数字";
    }

    @ExceptionHandler(ClassCastException.class)
    public String checkClassCastException(){
        return "ClassCastException类型转换异常";
    }

    @ExceptionHandler(ArrayIndexOutOfBoundsException.class)
    public String checkArrayIndexOutOfBoundsException(){
        return "ArrayIndexOutOfBoundsException数组下标超界";
    }

    @ExceptionHandler(NullPointerException.class)
    public String checkNullPointerException(){
        return "NullPointerException空指针异常";
    }

    @ExceptionHandler(SQLException.class)
    public String checkSQLException(){
        return "SQLException数据库异常";
    }

    @ExceptionHandler(IOException.class)
    public String checkIOException(){
        return "IOException IO流异常";
    }
}
